using System.Collections.Generic;
using Provausio.Common.Objects;
using TrainingManagement.api.Models.BusinessLogic.SkillSet;
using TrainingManagement.api.Models.Data.CRUD;
using TrainingManagement.api.Models.Data.CRUD.Position;

namespace TrainingManagement.api.Models.BusinessLogic.Position
{
    public class PositionSelectOperation : BusinessOperation<int?, List<BusinessObjects.Position>>
    {
        readonly PositionSelectDataSource _positionSelect = new PositionSelectDataSource();
        readonly SkillSetSelectOperation _skillSetSelect = new SkillSetSelectOperation();
        readonly PostionSkillSetSelectOperation _posSkillSetSelect = new PostionSkillSetSelectOperation();

        public override List<BusinessObjects.Position> Run(int? input)
        {
            return _positionSelect.Execute(input);
        }

        public List<BusinessObjects.Position> Run(int? input, bool loadSkillSets)
        {
            var result = Run(input);
            if (loadSkillSets)
            {
                foreach (var position in result)
                {
                    position.SkillSets = _posSkillSetSelect.Run(position.PositionId, true);
                }
            }
            return result;
        } 
    }
}